unit uTypesData;

{$mode objfpc}{$H+}

interface

uses
    Classes, SysUtils, contnrs,
    uInterfaces;

type

    { TISDataItem }

    TISDataItem = class(TISInterfacedObject, IISDataItem)
    private
        FCaption: string;
        FVisible: boolean;
    protected
        function GetCaption: string;
        procedure SetCaption(const ACaption: string);
        function GetVisible: boolean;
        procedure SetVisible(const AVisible: boolean);
    public
        property Caption: string read GetCaption write SetCaption;
        property Visible: boolean read GetVisible write SetVisible;
    end;

    { TISDataListItem }

    TISDataListItem = class(TISDataItem, IISDataListItem)
    private
        FOwnerList: IISDataList;
    protected
        function GetOwnerList: IISDataList;
        procedure SetOwnerList(const AList: IISDataList);
    public
    end;

    { TISDataTreeItem }

    TISDataTreeItem = class(TISDataListItem, IISDataTreeItem)
    private
        FOwnerTree: IISDataTree;
        FChildList: IISDataList;
    protected
        procedure Init; override;
        procedure Done; override;

        function GetOwnerTree: IISDataTree;
        procedure SetOwnerTree(const AList: IISDataTree);

        function GetChildList: IISDataList;
    public
    end;

    { TISDataList }

    TISDataList = class(TISInterfacedObject, IISDataList)
    private
        FList: TFPObjectList;
    protected
        procedure Init; override;
        procedure Done; override;

        procedure AddItem(const AItem: IISDataListItem); virtual;
        procedure DeleteItem(const AIndex: Integer); virtual;
        function GetItemIndex(const AItem: IISDataListItem): Integer;
        function GetItem(const AIndex: Integer): IISDataListItem;

        function GetCount: Integer;
    public
    end;

    { TISDataTreeList }

    TISDataTreeList = class(TISDataList, IISDataTreeList)
    private
        FOwnerItem: IISDataTreeItem;
        FOwnerTree: IISDataTree;
    protected
        function GetOwnerItem: IISDataTreeItem;
        function GetOwnerTree: IISDataTree;
    public
    end;

    { TISDataTree }

    TISDataTree = class(TISInterfacedObject, IISDataTree)
    private
        FRoot: IISDataTreeList;
    protected
        procedure Init; override;
        procedure Done; override;

        function GetRoot: IISDataList;
        function GetCount: Integer;
        function GetItem(const AIndex: Integer): IISDataTreeItem;
        function GetItemIndex(const AItem: IISDataTreeItem): Integer;
    public
        constructor Create;
        destructor Destroy; override;
    end;

implementation

{ TISDataTreeList }

function TISDataTreeList.GetOwnerItem: IISDataTreeItem;
begin
    Result := FOwnerItem;
end;

function TISDataTreeList.GetOwnerTree: IISDataTree;
begin
    Result := FOwnerTree;
end;

{ TISDataTreeItem }

procedure TISDataTreeItem.Init;
begin
    inherited Init;

    FChildList := TISDataList.Create;
end;

procedure TISDataTreeItem.Done;
begin
    (FChildList as TISDataList).Free;

    inherited Done;
end;

function TISDataTreeItem.GetOwnerTree: IISDataTree;
begin

end;

procedure TISDataTreeItem.SetOwnerTree(const AList: IISDataTree);
begin

end;

function TISDataTreeItem.GetChildList: IISDataList;
begin

end;

{ TISDataListItem }

function TISDataListItem.GetOwnerList: IISDataList;
begin
    Result := FOwnerList;
end;

procedure TISDataListItem.SetOwnerList(const AList: IISDataList);
begin
    FOwnerList := AList;
end;

{ TISDataTree }

procedure TISDataTree.Init;
begin
    inherited Init;

    FRoot := TISDataTreeList.Create;
end;

procedure TISDataTree.Done;
begin
    (FRoot as TISDataTreeList).Free;

    inherited Done;
end;

function TISDataTree.GetRoot: IISDataList;
begin
    Result := FRoot;
end;

function TISDataTree.GetCount: Integer;
begin

end;

function TISDataTree.GetItem(const AIndex: Integer): IISDataTreeItem;
begin

end;

function TISDataTree.GetItemIndex(const AItem: IISDataTreeItem): Integer;
begin

end;

constructor TISDataTree.Create;
begin
    inherited;

end;

destructor TISDataTree.Destroy;
begin
    (FRoot as TISDataList).Free;

    inherited
end;

{ TISDataList }

procedure TISDataList.Init;
begin
    inherited Init;

    FList := TFPObjectList.Create;
end;

procedure TISDataList.Done;
begin
    FList.Free;

    inherited Done;
end;

procedure TISDataList.AddItem(const AItem: IISDataListItem);
begin
    FList.Add(AItem as TObject);
    AItem.SetOwnerList(Self);
end;

procedure TISDataList.DeleteItem(const AIndex: Integer);
begin
    FList.Delete(AIndex);
end;

function TISDataList.GetItemIndex(const AItem: IISDataListItem): Integer;
begin
    Result := FList.IndexOf(AItem as TObject);
end;

function TISDataList.GetItem(const AIndex: Integer): IISDataListItem;
begin
    Result := FList[AIndex] as IISDataListItem;
end;

function TISDataList.GetCount: Integer;
begin
    Result := FList.Count;
end;

{ TISDataItem }

function TISDataItem.GetCaption: string;
begin
    Result := FCaption;
end;

procedure TISDataItem.SetCaption(const ACaption: string);
begin
    FCaption := ACaption;
end;

function TISDataItem.GetVisible: boolean;
begin
    Result := FVisible;
end;

procedure TISDataItem.SetVisible(const AVisible: boolean);
begin
    FVisible := AVisible;
end;

end.

